<template>
    <div class="login_container">
        <div class="login_form">
            <h3 class="title">后台管理系统</h3>
            <el-form ref="formRef" :model="loginForm" label-width="auto"> 
               <el-form-item prop="username">
                    <el-input
                        v-model="loginForm.username"
                        placeholder="请输入用户名"
                    >
                    <template #prefix>
                        <icon-ep-Avatar></icon-ep-Avatar>
                    </template>
                    </el-input>
               </el-form-item>
               <el-form-item prop="password">
                    <el-input
                        v-model="loginForm.password"
                        type="password"
                        placeholder="请输入密码"
                        show-password
                    >
                    <template #prefix>
                        <icon-ep-Key></icon-ep-Key>
                    </template>
                    </el-input>
               </el-form-item>
               <el-form-item>
                <div class="remember">
                    <el-checkbox v-model="loginForm.remember" label="记住我" />
                    <el-text type="primary">
                        忘记密码？
                    </el-text>
                </div>
               </el-form-item>
                <el-divider>
                    其他登录方式
                </el-divider>
                <div class="otherLogin">
                    <icon-ep-apple />
                    <icon-ep-ChromeFilled />
                    <icon-ep-Comment />
                </div>
                <el-form-item>
                    <el-button type="primary" @click ="handleLogin" class="loginBtn">登录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script setup>
import { login } from '@/api/auth';
import { setToken } from '@/utils/token';
    const loginForm = ref ({
        "username": "",
        "password": "",
        "remember": false
    })
    function handleLogin() {
        login(loginForm.value)
        .then(data => {
            console.log(data);
            //保存token 以键值对的数据存储
            setToken("token",data.data);
        })
    }
</script>

<style lang="scss" scoped>
.otherLogin {
    width: 100%;
    display: flex;
    justify-content: space-evenly;
}
.remember {
    width: 100%;
    display: flex;
    justify-content: space-between;
}
.login_container {
    background-image: url("@/assets/img/login_big.jpg");
    background-size: 100%;
    height: 100vh;
    display: flex;
    justify-content: flex-end;
    .login_form {
        display: flex;
        flex-direction: column;
        width: 50%;
        background-color: rgb(244, 247, 250);
        justify-content: center;
        align-items: center;
        // opacity: 0.5;
        .title {
            margin-bottom: 20px;
        }
        .el-form {
            width: 60%;
            .loginBtn {
                width: 100%;
                margin: 15px auto;
            }
        }
    }
}
</style>